package com.yesep.learn.design.behavioral.strategy;

import com.yesep.learn.design.common.pojo.*;

import java.util.*;

public class StrategyB implements IStrategy {
    public final static int threshold = 50; // 满减门槛
    public final static int reduction = 10; // 减少金额

    @Override
    public String getLabel() {
        return "每满50元减10元";
    }

    public double calculateTotalPrice(List<Goods> goodsList) {
        // 计算可以减免的次数
        int totalPrice = goodsList.stream().mapToInt(Goods::getPrice).sum();
        int reductionCount = (int) Math.floor(totalPrice / threshold);
        double totalReduction = reductionCount * reduction;
        double price = totalPrice - totalReduction;
        System.out.printf("The %s %s calculate total price %s. \n", this.getClass().getSimpleName(), getLabel(), price);
        return price;
    }
}
